<?php

namespace App\Http\Requests\Api;

use Illuminate\Database\Query\Builder;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class HpiSubUpdateRequest extends DrugStoreRequest
{
    /**
     * Determine if the user is authorized to make this request.
     * @return bool
     */
    public function authorize()
    {
        return \Auth::check();
    }

    /**
     * Get the validation rules that apply to the request.
     * @return array
     */
    public function rules()
    {
        $rules = parent::rules();

        $rules['id'] = [
            'required', 'integer', 'min:1',
            Rule::exists('st_medical_presentillness_sub', 'id')->where(function (Builder $query) {
                $query->whereNull('deleted_at')->where('record_id', $this->input('record_id'));
            })
        ];

        unset($rules['record_id']);


        return $rules;
    }
}
